%%
i = teachimage('mantelpiece.bmp');
f1 = figure; imshow(i);

e = edge(i, 'canny', [0.1 0.2], 2);
figure; imshow(e);

[h, theta, rho] = hough(e);
figure; imshow(sqrt(h'), []);

p = houghpeaks(h, 21, 'Threshold', 0, 'NhoodSize', [27 11]);

theta = (pi/180)*theta;
figure(f1);           % original image window

[nr, nc] = size(i);
hold on               % plot on top of image
for pr = p'           % pr is assigned each row of p in turn
    r = rho(pr(1));   % look up rho for the current line
    t = theta(pr(2)); % look up theta for the current line
    l = line_box(1, nc, 1, nr, r, t);   % get end points
    if ~isempty(l)
        plot(l([1 3]), l([2,4]), 'r-', 'LineWidth', 1);
    end
end
hold off


